home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CBASE102.ARJ / BCLOSE.C < prev    next >
Text File  |  1991-09-23  |  2KB  |  85 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)bclose.c    1.5 - 91/09/23" */
  5.  
  6. #include <ansi.h>
  7.  
  8. /* ansi headers */
  9. #include <errno.h>
  10. #ifdef AC_STRING
  11. #include <string.h>
  12. #endif
  13.  
  14. /* local headers */
  15. #include "blkio_.h"
  16.  
  17. /*man---------------------------------------------------------------------------
  18. NAME
  19.      bclose - close a block file
  20.  
  21. SYNOPSIS
  22.      #include <blkio.h>
  23.  
  24.      int bclose(bp)
  25.      BLKFILE *bp;
  26.  
  27. DESCRIPTION
  28.      The bclose function causes any buffered data for the block file
  29.      associated with BLKFILE pointer bp to be written out, and the
  30.      block file to be closed.
  31.  
  32.      bclose will fail if one or more of the following is true:
  33.  
  34.      [EINVAL]       bp is not a valid BLKFILE pointer.
  35.      [BENOPEN]      bp is not open.
  36.  
  37. SEE ALSO
  38.      bexit, bopen, bsync.
  39.  
  40. DIAGNOSTICS
  41.      Upon successful completion, a value of 0 is returned.  Otherwise,
  42.      a value of -1 is returned, and errno set to indicate the error.
  43.  
  44. ------------------------------------------------------------------------------*/
  45. #ifdef AC_PROTO
  46. int bclose(BLKFILE *bp)
  47. #else
  48. int bclose(bp)
  49. BLKFILE *bp;
  50. #endif
  51. {
  52.     /* validate arguments */
  53.     if (!b_valid(bp)) {
  54.         errno = EINVAL;
  55.         return -1;
  56.     }
  57.  
  58.     /* check if not open */
  59.     if (!(bp->flags & BIOOPEN)) {
  60.         errno = BENOPEN;
  61.         return -1;
  62.     }
  63.  
  64.     /* synchronize file with buffers */
  65.     if (bsync(bp) == -1) {
  66.         BEPRINT;
  67.         return -1;
  68.     }
  69.  
  70.     /* close file */
  71.     if (b_uclose(bp) == -1) {
  72.         BEPRINT;
  73.         return -1;
  74.     }
  75.  
  76.     /* free memory allocated for block file */
  77.     b_free(bp);
  78.  
  79.     /* scrub slot in biob table then free it */
  80.     memset(bp, 0, sizeof(*biob));
  81.     bp->flags = 0;
  82.  
  83.     return 0;
  84. }
  85.